﻿using System;
using Cobra.ErpConnectBL.Interfaces;
using BpNTClass.IOAblauf;

namespace BpNTClass.DebugOutput
{
    internal static class writeln : Object
    {
        //private static readonly BpNTClass.IOAblauf.bpWriter _Logger = new BpNTClass.IOAblauf.bpWriter();
        private static readonly log4net.ILog _Logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

        public static void Logger(string aString) // Std Logging 
        {
#if DEBUG
            System.Diagnostics.Debug.Write(System.Diagnostics.Process.GetCurrentProcess().Id.ToString() + " "); //+ " <<>> " + System.Threading.Thread.CurrentThread.ToString());
            System.Diagnostics.Debug.Write(aString);
            System.Diagnostics.Debug.Write("\r\n");
            LogAblauf.LogToLauf(aString);
#endif
            _Logger.Debug(aString);
        }

        public static void Error(string aString, Exception aException) // Std Exception Logging
        {
#if DEBUG
            System.Diagnostics.Debug.Write(System.Diagnostics.Process.GetCurrentProcess().Id.ToString() + " "); //+ " <<>> " + System.Threading.Thread.CurrentThread.ToString());
            System.Diagnostics.Debug.Write(aString + " Exception: " + aException.Message + " " + aException.Source + " " + aException.StackTrace);
            System.Diagnostics.Debug.Write("\r\n");
            LogAblauf.LogToLauf(aString + " Exception: " + aException.Message + " " + aException.Source + " " + aException.StackTrace);
#endif
            _Logger.Error(aString, aException);
        }

        public static void Prog(string aString) // Nur unter Debug Kompilat sichtbar
        {
#if DEBUG
            System.Diagnostics.Debug.Write(System.Diagnostics.Process.GetCurrentProcess().Id.ToString() + " "); //+ " <<>> " + System.Threading.Thread.CurrentThread.ToString());
            System.Diagnostics.Debug.Write(aString);
            System.Diagnostics.Debug.Write("\r\n");
            LogAblauf.LogToLauf(aString);
#endif
        }

        public static void Values(IFieldValue[] aValues)
        {
#if DEBUG
            string Ausgabe;
            Ausgabe = "";
            if (aValues != null)
            {
                foreach (IFieldValue Element in aValues)
                { Ausgabe = Ausgabe + "|" + Element.Value; }
                System.Diagnostics.Debug.Write("Next Value: " + Ausgabe + "\r\n");
            }
            else
            { System.Diagnostics.Debug.Write("Next Value: WAR NULL \r\n"); }
            System.Diagnostics.Debug.Write("******************************************\r\n");
#endif
        }

        public static void Ablauf(object FktPointer)
        {
#if DEBUG
            LogAblauf.LogToLauf(FktPointer);
#endif
        }
    }

    public static class LogAblauf
    {

        private static frmWriteln WRFrm = new frmWriteln();

        public static bool LogToLauf(string aInput)
        {
            bool Erfolg;
            Erfolg = false;
            WRFrm.Writeln(aInput);
            return Erfolg;
        }
        public static bool LogToLauf(object aObject)
        {
            bool Erfolg;
            Erfolg = false;
            WRFrm.Writeln(aObject);
            return Erfolg;
        }
    }

}
